<?php
namespace app\api\model;

use app\common\helper\Obj2Array;
use app\common\model\project_model\AppletImgModel;
use app\common\model\project_model\BasicConfigModel as Basic;
use think\Model;

class BasicConfigModel extends Basic {

    /**
     * 公用配置信息
     * @param $app_id
     * @param null $fields
     * @return bool
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public static function config($app_id, $fields = null) {
        if ($fields) {
            $field = $fields;
        } else{
            $field = '*';
        }
        $basicM = new self();
        // 获取小程序的头像
        $appletImgM = new AppletImgModel();
        $applet_img = $appletImgM->field('applet_img')->where(['applet_id' => $app_id, 'status' => AppletImgModel::STATUS_OK])->find();
        $config =$basicM->field($field)->where(['status' => $basicM::STATUS_OK, 'applet_app_id' => $app_id])->order(['updated_time' => 'DESC'])->find();
        if (empty($config)) {
            return false;
        }
        if (empty($applet_img)) {
            return $config;
        }
        if (!empty($applet_img) && !empty($config)) {
            return array_merge($applet_img->getData(), $config->getData());
        }
    }
}